package com.woniu.springbootrbac.controller;


import com.woniu.springbootrbac.dto.PerDto;
import com.woniu.springbootrbac.service.PerService;
import com.woniu.springbootrbac.util.Result;
import com.woniu.springbootrbac.vo.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Permission")
public class PermissionController {

    @Autowired
    private PerService service;
    @GetMapping("{rid}")
    public Result queryAll(@PathVariable Integer rid){
        List<TreeNode> treeNodes = service.selectAllPer(0);
        List<Integer> defautlChecked = service.selectPerByRid(rid);
        return Result.ok().data("permissionList",treeNodes).data("defaultChecked",defautlChecked);
    }
    @PostMapping("")
    public Result insertPer(@RequestBody PerDto perDto){
        service.insertPermission(perDto);
        return Result.ok();
    }

}
